#!/bin/sh

wikidir="/usr/share/doc/arch-wiki/html/en/"
wikidocs="$(find ${wikidir} -iname "*.html")"

main () {
	choice=$(printf '%s\n' "${wikidocs[@]}" | \
		cut -d '/' -f8- | \
		sed -e 's/_/ /g' -e 's/.html//g' | \
		sort | \
		dmenu -i -l 20 -p "Arch Wiki") || exit
	if [ "$choice" ]; then
		article=$(printf '%s\n' "$wikidir$choice.html" | sed 's/ /_/g')
		xdg-open "$article" # should run from the $BROWSER env-var
	fi
}

main
